﻿using System;

namespace DotNetCommon.Validate.Annotations;

/// <summary>
/// 字符串必须为null或者是空字符串, 示例:
/// <code>
/// [VMustBeNullOrEmpty]
/// public string OtherInfo { get; set; }
/// </code>
/// </summary>
/// <remarks>注意: 当属性不是字符串时, 会先调用 ToString() 转为字符串再进行判断, 这可以用于对非字符串类型的校验</remarks>
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
public class VMustBeNullOrEmptyAttribute(string errorMessage = null) : Attribute, IValidateAction
{
    public string ErrorMessage { get; internal set; } = errorMessage;

    public void Action(IValidateContext ctx)
    {
        ValidateStringExtensions.MustBeNullOrEmptyInternal(ctx, ErrorMessage);
    }
}
